<template>
	<!-- 数据变化列表组件 -->
	<view class="container">
		<table>
			<tr class="border">
				<th class="wid20 left">序号</th>
				<th class="wid20 left">数值</th>
				<th class="wid20 left">状态</th>
				<th class="wid40 right">更新时间</th>
			</tr>
			<!-- 循环每条数据 -->
			<tr v-for="(item, index) in listData" :key="index" v-if="index < top">
				<td class="wid20 left" >{{index | formatNum}}</td>
				<td class="wid20 left" >{{item.number}}</td>
				<td class="wid20 left" :class='[item.status == 0 ? "" : "orange"]'>{{item.status == 0 ? "正常" : "异常"}}</td>
				<td class="wid40 right">{{item.time}}</td>
			</tr>
		</table>
		<view class="btn" @tap="getMore" v-if="showBtn">
			<text>更多数据</text>
			<image :src="moreIcon"></image>
		</view>
	</view>
</template>

<script>
	export default {
		filters: {
			formatNum(n) {
				n = (n+1).toString()
				return n[1] ? n : '0' + n
			}
		},
		props: {
			list: {
				type: Array,
				default () {
					return []
				}
			},
			showBtn: {
				type: Boolean,
				default: false
			},
			top: {
				type: Number,
				default: Number.MAX_VALUE
			}
		},
		
		
		data() {
			return {
				listData: [],
				moreIcon: '../../static/image/monitor/arrow.png'
			}
		},
		mounted() {
			this.listData = this.list
		},
		methods: {
			// 更多数据
			getMore() {
				this.$emit("click")
			}
		}
	}
</script>

<style lang="scss">
	.container {
		display: flex;
		flex-direction: column;
		background-color: #fff;
		table {
			font-size: 26rpx;
			tr {
				display: flex;
				flex-direction: row;
				white-space: nowrap;
				
			}
			th,td {text-align:center;}
			
			th {
				height: 60rpx;
				line-height: 60rpx;
				color: #999;
			}
			td {
				height: 80rpx;
				line-height: 80rpx;
				white-space: nowrap;
				overflow: hidden;
				color: #333;
			}
			.wid20{
				width: 20%;
			}
			.wid40{
				width: 40%;
			}
			.right {
				text-align: right;
			}
			.left {
				text-align: left;
			}
			.border {
				border-bottom: 2rpx solid #F5F6F9;
			}
			.orange {
				color: #FF7547;
			}
		}
	.btn {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 66rpx;
		color: #1DD3B8;
		font-size: 26rpx;
		
		image {
			width: 23rpx;
			height: 23rpx;
			margin-left: 6rpx;
		}
		}
	}
</style>
